
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<head>
	<title><fmt:message key="user.modify" />
	</title>
	<meta name="heading" content="<fmt:message key='user.heading'/>" />
	<meta name="menu" content="UserMenu" />
	<script type="text/javascript" src="<c:url value='/js/global.js'/>"></script>
	<script type="text/javascript"
		src="<c:url value='/js/selectOperation.js'/>"></script>
	<script type="text/javascript"
		src="<c:url value='/js/prototype.js'/>"></script>
</head>
<body>
<div id="main"> 
</div>
	<html:form name="userForm" action="saveUser" method="post"
		validate="true">
		<html:hidden key="user.id" />
		<input type="hidden" name="from" value="${param.from}"/>
		<html:hidden key="user.version" />
		
		<html:hidden key="user.credentialsExpired" />
		<html:if test="user.version == null">
			<input type="hidden" name="encryptPass" value="true" />
		</html:if>
		<p align="center">
			<fmt:message key="user.modify" />
		</p>
		<table align="center" cellpadding="0" cellspacing="0" width="80%">
			<tr>
				<td colspan="2">
					<c:set var="buttons">
						<html:submit key="button.save" method="save"
							onclick="onFormSubmit(this.form)" labelposition="bottom" />
					
						<c:if test="${user.id !=0}">
					&nbsp;&nbsp;&nbsp;&nbsp;
					<html:submit key="button.delete" method="delete"
								onclick="return confirmDelete('user')" labelposition="bottom" />
						</c:if>
						&nbsp;&nbsp;&nbsp;&nbsp;
					<html:submit key="button.cancel" method="cancel"
							labelposition="bottom"  onclick="javascript:history.back(-1);"/>
					</c:set>
					<c:out value="${buttons}" escapeXml="false" />
				</td>
			</tr>
			<tr>
				<td><html:checkbox key="user.enabled" cssClass="text large" labelposition="bottom" />
				</td>
				<td><html:checkbox key="user.accountExpired" cssClass="text large" labelposition="bottom" />
				</td>
			</tr>
			<tr>
				<td><html:checkbox key="user.accountLocked" cssClass="text large" labelposition="bottom" />
				</td>
				<td><html:checkbox key="user.system" cssClass="text large" labelposition="bottom" />
				</td>
			</tr>
			<tr>
				<td>
					<html:textfield key="user.username" cssClass="text large"
						required="true" labelposition="bottom" />
				</td>
				<td>
					<html:textfield key="user.name" cssClass="text medium"
						required="true" labelposition="bottom" />
				</td>
			</tr>
			<tr>
				<td>

					<html:password key="user.password" required="true"
						cssClass="text large" labelposition="bottom" showPassword="true" />
				</td>
				<td>
					<html:password key="user.confirmPassword" required="true"
						showPassword="true" cssClass="text large" labelposition="bottom"
						onchange="passwordChanged(this)" />

				</td>
			</tr>
			<tr>
				<td>
					<html:textfield key="user.phoneNumber" cssClass="text medium"
						labelposition="bottom" />
				</td>
				<td>
					<html:textfield key="user.website" required="true"
						cssClass="text large" labelposition="bottom" />
				</td>
			</tr>
			<tr>
				<td>
					<html:textfield key="user.address" cssClass="text large"
						labelposition="bottom" />
				</td>
				<td>
					<html:textfield key="user.email" required="true"
						cssClass="text medium" labelposition="bottom" />
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<strong><fmt:message key="user.roles" />:</strong>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<table width="100%" cellpadding="0" cellspacing="0">
						<tr>
							<td width="301">
								<select id="saveUser_user_roles" name="user.roles"
									style="width:100%;"
									onclick="javascript:onClickSelect(this,document.all['troles']);"
									size="5">
									<c:forEach items="${userRoles}" var="role">

										<option value="${role.roleId}">
											${role.name}
										</option>
									</c:forEach>
								</select>
							</td>
							<td width="40">
								<br>
							</td>
							<td width="435">
								<select id="troles" name="troles" size="5" style="width:100%;"
									onclick="javascript:onClickSelect(this,document.all['saveUser_user_roles']);">
									<c:forEach items="${roles}" var="role">

										<option value="${role.id}">
											${role.name}
										</option>
									</c:forEach>
								</select>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<c:out value="${buttons}" escapeXml="false" />
				</td>
			</tr>
		</table>
	</html:form>
</body>
<script type="text/javascript">
    //Form.focusFirstElement(document.forms["userForm"]);
    function passwordChanged(passwordField) {
        if (passwordField.name == "user.password") {
            var origPassword = "<html:property value="user.password"/>";
        } else if (passwordField.name == "user.confirmPassword") {
            var origPassword = "<html:property value="user.confirmPassword"/>";
        }
        
        if (passwordField.value != origPassword) {
            createFormElement("input", "hidden",  "encryptPass", "encryptPass","true", passwordField.form);
        }
    }
</script>
